mybatis plus 多模块扫描xml文件 当前模块扫描 子模块扫描(BindingException: Invalid bound statement (not found)) 您所在的位置:网站首页 java 多模块path扫描不到 mybatis plus 多模块扫描xml文件 当前模块扫描 子模块扫描(BindingException: Invalid bound statement (not found))

mybatis plus 多模块扫描xml文件 当前模块扫描 子模块扫描(BindingException: Invalid bound statement (not found))

2024-07-12 09:04| 来源: 网络整理| 查看: 265

为了实现代码的复用,我们采用了多模块开发的方式,将通用的方法封装到 api-service 模块下,目录结构如下:

api-service 核心文件介绍: 

MybatisPlusConfig:

/** * 自定义 mybatis 配置;扫描 mapper.java 文件*/ @Configuration @MapperScan("com.zlhc.api.mapper") public class MybatisPlusConfig

ConfigurationBean:

/** * 采用路径扫描的方式 @ComponentScan 或者 @Bean 注册的方式将对象添加到引用该 jar 包的 spring 容器*/ @Configuration @ComponentScan("com.zlhc.api") public class ConfigurationBean

src/main/resources/META-INF/spring.factories:注意路径是固定的

# spring-core包里定义了SpringFactoriesLoader类,这个类实现了检索META-INF/spring.factories文件,并获取指定接口的配置的功能 org.springframework.boot.autoconfigure.EnableAutoConfiguration=com.zlhc.api.config.ConfigurationBean

将特殊定义的代码,作为主模块调用 api-service 模块,目录结构如下:

 api-app 关键文件介绍: 

pom.xml:

api-service com.zlhc ${project.version}

application.yml:

mybatis-plus: # 指定sql映射文件位置 mapper-locations: - classpath*:mybatis/mapper/*.xml # 扫描子模块下的 mapper.xml文件 - classpath:mybatis/mapper/*.xml # 扫描当前模块下的 mapper.xml 文件 # 实体对象的扫描包 type-aliases-package: com.zlhc.api.entity global-config: db-config: # id 生成策略全局配置, 雪花算法 id-type: ASSIGN_ID # 不显示 banner banner: false # 开启驼峰命名 configuration: map-underscore-to-camel-case: true

报 org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): com.zlhc.api.mapper.DemoMapper.getMinTimestamp 如何解决:

1.首先检查有没有添加扫描

# 指定sql映射文件位置 mapper-locations: - classpath*:mybatis/mapper/*.xml # 扫描子模块下的 mapper.xml文件(其实只写这一个就可以,要是扫描不到当前模块下的xml文件,再去添加下面的试试) - classpath:mybatis/mapper/*.xml # 扫描当前模块下的 mapper.xml 文件

2. 检查 xml 路径名是否错误,我就写成 mybatis.mapper,所以一直报错,希望大家不要犯我这个蠢错误



【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

    专题文章
      CopyRight 2018-2019 实验室设备网 版权所有